<style>
  .order_status{
    margin-left: 0.2rem;
  }
  .order_status>span{
    color: #cb2527;
  }
  .btn-shipping{
    font-size: 10px;
    float: right;
    padding: 1px;
  }
</style>

<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
<header class="mui-bar mui-bar-nav header">
  <h1 class="mui-title">订单详情</h1>
</header>
<div class="mui-content">
  <h5 class="order-tit">收货人信息</h5>
  <div class="order-name">
    <a href="gladdress.html">
      <p>收件人：<%= contact.name%>    电话：<%= contact.tel%>    地址：<%= contact.addr%></p>
    </a>
    <i class="am-icon-angle-right"></i>
  </div>
  <div class="h10"></div>
  <h5 class="order-tit">确认订单信息</h5>
  <ul class="shopcart-list" style="padding-bottom: 0; margin-top: 0;">
    <% var total = 0;%>
    <% for(var i=0; i<p_list.length; i++){%>
    <% total += Number(p_list[i].amount)%>
    <li>
      <img src="http://auewe.oss-ap-southeast-2.aliyuncs.com/products/<%= p_list[i].sn%>_thumb.jpeg" class="shop-pic">
      <div class="order-mid">
        <div class="tit"><%= p_list[i].print_name%></div>
        <div class="order-price">$<%= p_list[i].price.toFixed(2)%> <i>x<%= p_list[i].quantity%></i></div>
      </div>
    </li>
    <% }%>
  </ul>
  <% var shipping_fee = Number(order.total_amount) - total%>
  <ul class="order-infor">
    <li class="order-infor-first">
      <span>商品总计：</span>
      <i>$<%= total%></i>
    </li>
    <li class="order-infor-first">
      <span>运费：</span>
      <i>$<%= shipping_fee.toFixed(2)%></i>
    </li>
    <li class="order-infor-first">
      <span>订单总计：</span>
      <i>$<%= order.total_amount%></i>
    </li>
  </ul>
  <div class="h10"></div>
  <div class="order_status">
    订单状态：<span><%= status%></span>
    <% var box = JSON.parse(box_sn);%>
    <% if (box.length > 0 && box[0].sn != 'undefined') {%>
    <a class="mui-btn mui-btn-warning btn-shipping" href="/orders/<%= box[0].sn%>/shipping/">查看物流信息</a>
    <%}%>
  </div>
  <div class="h10"></div>
  <div class="jl"></div>
  <div class="shop-fix">
    <div class="order-text">
      应付总额：<span>$<%= order.total_amount%></span>
    </div>
    <div class="js-btn" style="display: none;">支付</div>
  </div>
  <div class="mui-backdrop" style="display: none;"></div>
  <div class="g-detail" >
    <div class="g-detail-top" style="display: none">
      <div class="g-detail-close"><i class="iconfont">&#xe625;</i></div>
    </div>
    <div class="g-detail-num">
      <h2 class="fl">支付方式</h2>
      <div class="fr">
        <div id="payment_method">
          <button class="mui-btn" type="button">微信支付</button>
          <button class="mui-btn" type="button">银行转账</button>
        </div>
      </div>
    </div>
    <div class="g-detail-btn">
      确定
    </div>
  </div>
</div>
<script>
  $(function(){
    var status = '<%= order.status%>';
    if (status != '5') {
        $('.js-btn').css('display', 'none');
    } else {
        $('.js-btn').css('display', 'block');
    }
    $(".js-btn").click(function(){
      $(".mui-backdrop").show();
      $(".g-detail").slideDown();
    })
    $(".g-detail-close").click(function(){
      $(".mui-backdrop").hide();
      $(".g-detail").slideUp();
    })
  });
  $(function () {
    $('#payment_method>button').click(function () {
      $(this).siblings('.mui-btn').removeClass('mui-btn-success');
      $(this).addClass('mui-btn-success');
    })
  });
  $('.g-detail-btn').click(function () {
    var payment_method = $('.mui-btn-success').text();
    console.log(payment_method);
    if (payment_method == '') {
        alert('未选择支付方式');
    } else {
        if (payment_method == '微信支付') {
            $.post('/payment/<%= order.id%>', {order_id: '<%= order.id%>', order_title: '订单<%= order.id%>', price: Number('<%= order.total_amount%>')*100, openid: sessionStorage.getItem('openid')}, function (call) {
              if (call.status == 'success') {
                  window.location.href = call.pay_uri;
              }
            })
        } else {
//          wx.chooseImage({
//            count: 1,
//            sizeType: ['original', 'compressed'],
//            sourceType: ['album', 'camera'],
//            success: function (res) {
//              var localIds = res.localIds;
//            }
//          });
          window.location.href='/transfer/<%= order.id%>';
        }
    }
  })
</script>
